package cn.jia.activemq;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

import javax.jms.*;
import javax.print.attribute.standard.Destination;

/**
 * @Author: jia
 * @Descirption:
 * @Date: 2018/4/19 15:44
 * @Modified By:
 */


public class SpringActiveMQTest {
    @Test
    public void testJmsTemplate() throws Exception {
        //获取jmsTemplate
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring-context-activeMQ.xml");
        JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
        //获取目的地
        Queue destination = (Queue) context.getBean("myQueue");
        //发送消息
        jmsTemplate.send(destination, new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                TextMessage textMessage = session.createTextMessage("spring-queue");
                return textMessage;
            }
        });
    }
}
